float3 LightDir0;
float3 LightDir1;
float3 LightDir2;
float3 CameraPosition;

float4 DiffuseColor;
float3 EmissiveColor;	
float3 AmbientColor;			
float3 SpecularColor;
float SpecularPower;
float Shininess;

float4 Booleans01;				// x = Diffuse

// Structs
struct VS_OUTPUT
{
    float4 position				: POSITION;
	float2 textureCoords		: TEXCOORD0;
	float3 normalW				: TEXCOORD1;
	float3 tangentW				: TEXCOORD2;
	float3 binormalW			: TEXCOORD3;
	float3x3 halfLights			: TEXCOORD4;
};

// Samplers
sampler2D DiffuseSampler		: register(s0);
sampler2D BumpSampler			: register(s1);
sampler2D SpecularSampler		: register(s2);

// Shaders
float4 main(VS_OUTPUT In) : COLOR
{
	float3 baseColor = 1;
	float3 normalW = normalize(In.normalW);

	// Bump
	if (Booleans01.y == 1.0f)
	{
		float3 tangentW = In.tangentW;
		float3 binormalW = In.binormalW;
	    float3 normalSample = tex2D(BumpSampler, In.textureCoords).rgb;

		float3x3 bumpMatrix;
		bumpMatrix[0] = In.tangentW;
		bumpMatrix[1] = In.binormalW;
		bumpMatrix[2] = normalW;

		normalW = normalize(normalW + mul(normalSample, bumpMatrix));
	}

	if (Booleans01.x == 1.0f)
		baseColor = tex2D(DiffuseSampler, In.textureCoords).rgb;

	// Diffuse Lighting
	float ndl = (saturate(dot(normalW, -LightDir0)) 
		      + saturate(dot(normalW, -LightDir1))
		      + saturate(dot(normalW, -LightDir2))) * 0.4;
	float3 diffuse = DiffuseColor.rgb * ndl;

	// Specular Lighting	
	float3 specularColor = SpecularColor;
	float3 reflectionVector = normalize(In.halfLights[0]);
	float3 reflectionVector1 = normalize(In.halfLights[1]);
	float3 reflectionVector2 = normalize(In.halfLights[2]);
	float specComp = saturate((pow(saturate(dot(reflectionVector, normalW)), SpecularPower) + pow(saturate(dot(reflectionVector1, normalW)), SpecularPower)	+ pow(saturate(dot(reflectionVector2, normalW)), SpecularPower))) * Shininess;

	if (Booleans01.z == 1.0f)
		specularColor += tex2D(SpecularSampler, In.textureCoords).rgb;

	float3 specular =  specComp* specularColor;
	
	float4 ambientDiffEmm = float4(AmbientColor + EmissiveColor + (diffuse * baseColor), DiffuseColor.a);
	return ambientDiffEmm + float4(specular,1);
}